package pers.xx.sbm.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import pers.xx.sbm.service.UserRoleService;
import pers.xx.sbm.vo.ResResult;

import java.util.List;

/**
 * @author ：xiexing
 * @description：用户授权Controller
 * @date ：2020/8/17 14:18
 */
@Controller
@RequestMapping("/user_authorization")
public class UserAuthController {

    @Autowired
    private UserRoleService userRoleService;//用户角色

    /**
     * @description 用户授权页面
     * @author XieXing
     * @date 2020/8/11 15:45
     */
    @RequestMapping("/")
    public String userPage(Model model) {
        return "page/system/user_authorization";
    }

    /**
     * @description 设置用户权限
     * @author XieXing
     * @date 2020/10/13 15:47
     */
    @ResponseBody
    @RequestMapping(value = "/setUserAuth", method = RequestMethod.POST)
    public ResResult setUserAuth(Integer userId, String roles) {
        return userRoleService.saveBatchUserRole(userId, roles);//根据用户id删除用户角色
    }


    /**
     * @description 根据用户id获取用户角色
     * @author XieXing
     * @date 2020/10/13 16:58
     */
    @ResponseBody
    @RequestMapping(value = "/getRoleIdsByUserId", method = RequestMethod.POST)
    public List<Integer> getRoleIdsByUserId(Integer userId) {
        return userRoleService.getRoleIdsByUserId(userId);
    }

}
